package router

import (
	"gin_tem/global"
	"gin_tem/internal/controller"
	"gin_tem/internal/service"
	"gin_tem/middlewares"
)

func InitUserRouter() {
	r := R.Group("/user")
	//1
	//调用controller.NewUserController  ===============》controller.NewUserController

	//2
	//传入service层中的NewUserService方法 ====================》service.NewUserService
	//service层中的NewUserService方法传入db数据库========================》service.NewUserService(global.DB)
	//返回userService层的结构体 该结构体实现了UserService接口 service.UserService

	//3 也就是说userService层的结构体 传入了NewUserController函数中=============> controller.NewUserController(service.NewUserService(global.DB))

	//4 调用NewUserController的Login.CreateUser.List函数=============>controller.NewUserController(service.NewUserService(global.DB)).Login

	//5 调用userService层的结构体对应的Login.CreateUser.List函数 ====================>uc.userService.Login

	//uc就是controller层中对应的结构体
	//.userService 获取到包含的userService结构体
	//然后调用userService的Login方法

	userController := controller.NewUserController(service.NewUserService(global.DB))
	{
		r.GET("/login", userController.Login)
		//注册
		r.GET("/create", userController.CreateUser)
		//查询用户列表 使用jwt中间件
		r.GET("list", middlewares.JwtParse(), userController.List)
	}
}
